/***********************************************************
* 
*     File Name:  rtpapa.cpp
* 
*        Author:  Algolc
* 
*          mail:  17360224@qq.com
* 
*  Created Time:  Fri 13 Jul 2018 02:08:52 PM CST
* 
***********************************************************/

#include "zhelpers.h"
#include <unistd.h>
int main() {
    void* context = zmq_ctx_new();
    assert(context);   
    void* client = zmq_socket(context, ZMQ_ROUTER);
    assert(client);   
    int ret = zmq_bind(client, "ipc://routing.ipc");
    assert(!ret);

    void* worker = zmq_socket(context, ZMQ_REP);
    assert(worker);
    zmq_setsockopt(worker, ZMQ_IDENTITY, "A", 1);
    ret = zmq_connect(worker, "ipc://routing.ipc");
    assert(!ret);
        
    //等待worker连接
    sleep(5);

    //发送REP的标识地址, 空帧, 以及消息内容
    s_sendmore(client, "A");
    s_sendmore(client, "address 3");
    s_sendmore(client, "address 2");
    s_sendmore(client, "address 1");
    s_sendmore(client, "");     //空帧
    s_sendmore(client, "This is the workload");

    //worker 只会得到消息内容
    s_dump(worker);     
    
    //worker 不需要处理信封
    s_send(worker, "This is the reply");

    //看看这边router里边收到了什么
    s_dump(client);

    zmq_close(client);
    zmq_close(worker);
    zmq_ctx_destroy(context);

    return 0;
}
